package com.web.shop.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.web.shop.pojo.PageReq;
import com.web.shop.pojo.PageResp;
import com.web.shop.pojo.RespBean;
import com.web.shop.pojo.TbBrand;
import com.web.shop.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ManagerController {
    @Autowired
    private BrandService brandService;

    //查询品牌
    @GetMapping("querybrand")
    public List<TbBrand> querybrand(){
        return brandService.findAll();
    }


    @RequestMapping("/findOne")
    public TbBrand findOne(Long id){
        return brandService.findOne(id);
    }
   // 增加修改品牌
    @PostMapping("/update")
    public RespBean update(@RequestBody TbBrand brand){
            brandService.update(brand);
            return  RespBean.ok("修改成功");

    }
//    //增加品牌
//    @PostMapping("/add")
//    public RespBean add(@RequestBody TbBrand brand){
//            brandService.add(brand);
//            return  RespBean.ok("增加成功");
//
//    }
    //删除品牌
    @RequestMapping("/delete/{id}")
    public RespBean delete(@PathVariable Long  id){
            brandService.delete(id);
            return  RespBean.ok("删除成功");

    }
    //查询+分页
    @GetMapping("/listByPage")
    public PageResp<TbBrand> listByPage(PageReq pageReq) {
        PageHelper.startPage(pageReq.getPage(),pageReq.getSize());
        Page<TbBrand> page = (Page<TbBrand>) brandService.findAll();
        PageResp pageResp = new PageResp();
        pageResp.setList(page.getResult());
        pageResp.setTotal(page.getTotal());
        return pageResp;
    }

}
